#include <vector>
#include <string>
#include <iostream>

using namespace std;

vector<char> lcs(const string &str1, const string &str2) {
  /*      str1
  str2
  */
  vector<vector<string>> table(str2.size() + 1, vector<string>(str1.size() + 1, ""));

  for (int r = 1; r < table.size(); ++r) {
    for (int c = 1; c < table[0].size(); ++c) {
      string tmp;
      if (str2[r - 1] == str1[c - 1]) {
        tmp += table[r - 1][c - 1];
        tmp += str2[r - 1];
        table[r][c] = tmp;
      }
      else {
        if (table[r - 1][c].size() > table[r][c - 1].size()) {
          tmp = table[r - 1][c];
        }
        else {
          tmp = table[r][c - 1];
        }

        table[r][c] = tmp;
      }
    }
  }

  return vector<char>(table.back().back().begin(), table.back().back().end());
}

int main(int argc, char const *argv[])
{
  /* code */

  string str1 = "XKYKZPW";
  string str2 = "ZXVVYZW";

  auto result = lcs(str1, str2);

  for (char c : result) {
    cout << c << " ";
  }
  cout << endl;

  return 0;
}
